<template>
	<view class="address">
		<view class="item" v-for="(res, index) in addressList" :key="res.id">
			<view class="top">
				<view class="left">

					<view class="name">{{ res.name }} <text class="phone">{{ res.mobile }}</text></view>
					{{ res.address }}
				</view>
				
				<view class="tag">
					<u-icon name="edit-pen" :size="26" color="#999999" @tap="editAddress(res.id)"></u-icon>
				</view>
			</view>
			<view class="bottom">
				<u-checkbox v-model="res.default">默认</u-checkbox>
				<text class="" @click="delSite()">删除</text>
			</view>
		</view>
		
		<view class="addSite">
			<u-button type="primary" shape="circle" @click="toAddSite()">
				新建收货地址
			</u-button>
		</view>
		
	</view>
</template>

<script>
	import {getAddressList,delAddress} from '@/api/api.js';

export default {
	data() {
		return {
			siteList: [],
			addressList: []
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		
		async getData() {
			await getAddressList().then((res) => {
				console.log(res);
				this.addressList = res;
			}).catch(() => {
					
			})
		},
		async delSite() {
		
			await delAddress().then((res) => {
				console.log(res);
				uni.$u.toast(res.msg);
			}).catch(() => {
					
			})
			
		},
		toAddSite(){
			uni.navigateTo({
			    url: '/pages/address/edit'
			});
		},
		editAddress(id){
			uni.navigateTo({
			    url: '/pages/address/edit?id=' + id
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.item {
	padding: 40rpx 20rpx;
	.top {
		display: flex;
		font-weight: bold;
		font-size: 34rpx;
		align-items: center;
		.phone {
			margin-left: 60rpx;
		}
		.tag {
			display: flex;
			font-weight: normal;
			align-items: center;
			justify-content: space-between;
			
			text {
				display: block;
				width: 60rpx;
				height: 34rpx;
				line-height: 34rpx;
				color: #ffffff;
				font-size: 20rpx;
				border-radius: 6rpx;
				text-align: center;
				margin-left: 30rpx;
				background-color:rgb(49, 145, 253);
			}
			.red{
				background-color:red
			}
		}
	}
	.bottom {
		display: flex;
		margin-top: 20rpx;
		font-size: 28rpx;
		justify-content: space-between;
		color: #999999;
	}
}
.addSite {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	width: 100%;
	background-color: #ffffff;
	z-index: 999;
	display: flex;
	align-items: center;
	padding: 30rpx;
	box-sizing: border-box;
	
	.add{
		display: flex;
		align-items: center;
		color: #ffffff;
		.icon{
			margin-right: 10rpx;
		}
	}
}
</style>
